package com.Darkra1Zzz.service.impl;

import com.Darkra1Zzz.dao.TypeDao;
import com.Darkra1Zzz.entity.PageInfo;
import com.Darkra1Zzz.entity.Type;
import com.Darkra1Zzz.service.TypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xzw
 * @date 2021/7/1 16:53
 */
@Service
public class TypeServiceImpl implements TypeService {
    @Resource
    private TypeDao typeDao;






    @Override
    public PageInfo<Type> findpageInfo(Type type, Integer pageIndex, Integer pageSize) {
        PageInfo<Type>pageInfo=new PageInfo<Type>();
        pageInfo.setPageIndex(pageIndex);
        pageInfo.setPageSize(pageSize);

        Integer totalCount =typeDao.countAllType(type);
        if (totalCount>0){
            pageInfo.setPageTotalCount(totalCount);
            List<Type> TypeList=typeDao.findTypeList(type.getId(),type.getName(),type.getType(type),
                    (pageInfo.getPageIndex() - 1) * pageInfo.getPageSize(), pageInfo.getPageSize());
            pageInfo.setList(TypeList);
        }
        return pageInfo;
    }

    @Override
//    int用不了改为了boolean
    public boolean deleteType(Integer id) {
        return typeDao.delete(id);
    }

    @Override
    //    int用不了改为了boolean
    public boolean addType(Type type) {
        return typeDao.insert(type);
    }

    @Override
    public int updateType(Type type) {
        return typeDao.update(type);
    }

    @Override
    public Type findTypeBYId(Integer id) {
        return null;
    }

    @Override
    public List<Type> getAll() {
        List<Type>typeList=typeDao.findAllType();

        return typeList;
    }
}
